#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

from datetime import datetime
from enum import Enum

from termcolor import colored


# 定义颜色枚举
class Color(Enum):
    BLACK = "black"
    GREY = "grey"  # Actually black but kept for backwards compatibility
    RED = "red"
    GREEN = "green"
    YELLOW = "yellow"
    BLUE = "blue"
    MAGENTA = "magenta"
    CYAN = "cyan"
    LIGHT_GREY = "light_grey"
    DARK_GREY = "dark_grey"
    LIGHT_RED = "light_red"
    LIGHT_GREEN = "light_green"
    LIGHT_YELLOW = "light_yellow"
    LIGHT_BLUE = "light_blue"
    LIGHT_MAGENTA = "light_magenta"
    LIGHT_CYAN = "light_cyan"
    WHITE = "white"


def print_loading(msg, i, max_dot=7):
    # 先清空行，再打印新的内容
    print(
        f"\r{' ' * (len(msg) + max_dot)}\r{msg}{"." * (i % max_dot)}",
        end="",
        flush=True,
    )


def print_success(*msg, sep=" ", color=Color.GREEN):
    """打印成功字符"""
    message = sep.join(map(str, msg))
    print(colored(message, color.value))


def print_error(*msg, sep=" ", color=Color.RED):
    """打印失败字符"""
    message = sep.join(map(str, msg))
    print(colored(message, color.value))


# 动态创建类
class DynamicClass:
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            if isinstance(value, dict):
                value = DynamicClass(**value)
            setattr(self, key, value)

    def __repr__(self):
        attributes = ", ".join(
            f"{key}={value!r}" for key, value in self.__dict__.items()
        )
        return f"{self.__class__.__name__}({attributes})"


# def class_from_dict(class_dict):
#     class_name = class_config.get("class_name")
#     base_classes = class_config.get("base_classes", (object,))
#     config = {
#         "attributes": class_config.get("attributes", {}),
#         "methods": class_config.get("methods", {}),
#     }
#     # 使用元类创建类
#     return DynamicClassMeta(class_name, base_classes, {}, class_dict)


# if __name__ == "__main__":
#     print_success("12312", "1212", sep="\n")


def get_first_day_of_quarter() -> str:
    # 获取当前日期
    now = datetime.now()
    # 获取当前年份和月份
    year = now.year
    month = now.month

    # 根据当前月份确定季度的第一天
    if month in [1, 2, 3]:
        first_day = datetime(year, 1, 1)  # 第一季度
    elif month in [4, 5, 6]:
        first_day = datetime(year, 4, 1)  # 第二季度
    elif month in [7, 8, 9]:
        first_day = datetime(year, 7, 1)  # 第三季度
    else:
        first_day = datetime(year, 10, 1)  # 第四季度

    return first_day.strftime("%Y-%m-%d")
